// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

#nullable restore
namespace Elastic.Clients.Elasticsearch.Ml
{
	public sealed partial class DataframeEvaluationRegressionMetrics
	{
		[JsonInclude]
		[JsonPropertyName("huber")]
		public Elastic.Clients.Elasticsearch.Ml.DataframeEvaluationRegressionMetricsHuber? Huber { get; set; }

		[JsonInclude]
		[JsonPropertyName("mse")]
		public Dictionary<string, object>? Mse { get; set; }

		[JsonInclude]
		[JsonPropertyName("msle")]
		public Elastic.Clients.Elasticsearch.Ml.DataframeEvaluationRegressionMetricsMsle? Msle { get; set; }

		[JsonInclude]
		[JsonPropertyName("r_squared")]
		public Dictionary<string, object>? RSquared { get; set; }
	}

	public sealed partial class DataframeEvaluationRegressionMetricsDescriptor : SerializableDescriptorBase<DataframeEvaluationRegressionMetricsDescriptor>
	{
		internal DataframeEvaluationRegressionMetricsDescriptor(Action<DataframeEvaluationRegressionMetricsDescriptor> configure) => configure.Invoke(this);
		public DataframeEvaluationRegressionMetricsDescriptor() : base()
		{
		}

		private Elastic.Clients.Elasticsearch.Ml.DataframeEvaluationRegressionMetricsHuber? HuberValue { get; set; }

		private DataframeEvaluationRegressionMetricsHuberDescriptor HuberDescriptor { get; set; }

		private Action<DataframeEvaluationRegressionMetricsHuberDescriptor> HuberDescriptorAction { get; set; }

		private Dictionary<string, object>? MseValue { get; set; }

		private Elastic.Clients.Elasticsearch.Ml.DataframeEvaluationRegressionMetricsMsle? MsleValue { get; set; }

		private DataframeEvaluationRegressionMetricsMsleDescriptor MsleDescriptor { get; set; }

		private Action<DataframeEvaluationRegressionMetricsMsleDescriptor> MsleDescriptorAction { get; set; }

		private Dictionary<string, object>? RSquaredValue { get; set; }

		public DataframeEvaluationRegressionMetricsDescriptor Huber(Elastic.Clients.Elasticsearch.Ml.DataframeEvaluationRegressionMetricsHuber? huber)
		{
			HuberDescriptor = null;
			HuberDescriptorAction = null;
			HuberValue = huber;
			return Self;
		}

		public DataframeEvaluationRegressionMetricsDescriptor Huber(DataframeEvaluationRegressionMetricsHuberDescriptor descriptor)
		{
			HuberValue = null;
			HuberDescriptorAction = null;
			HuberDescriptor = descriptor;
			return Self;
		}

		public DataframeEvaluationRegressionMetricsDescriptor Huber(Action<DataframeEvaluationRegressionMetricsHuberDescriptor> configure)
		{
			HuberValue = null;
			HuberDescriptor = null;
			HuberDescriptorAction = configure;
			return Self;
		}

		public DataframeEvaluationRegressionMetricsDescriptor Mse(Func<FluentDictionary<string, object>, FluentDictionary<string, object>> selector)
		{
			MseValue = selector?.Invoke(new FluentDictionary<string, object>());
			return Self;
		}

		public DataframeEvaluationRegressionMetricsDescriptor Msle(Elastic.Clients.Elasticsearch.Ml.DataframeEvaluationRegressionMetricsMsle? msle)
		{
			MsleDescriptor = null;
			MsleDescriptorAction = null;
			MsleValue = msle;
			return Self;
		}

		public DataframeEvaluationRegressionMetricsDescriptor Msle(DataframeEvaluationRegressionMetricsMsleDescriptor descriptor)
		{
			MsleValue = null;
			MsleDescriptorAction = null;
			MsleDescriptor = descriptor;
			return Self;
		}

		public DataframeEvaluationRegressionMetricsDescriptor Msle(Action<DataframeEvaluationRegressionMetricsMsleDescriptor> configure)
		{
			MsleValue = null;
			MsleDescriptor = null;
			MsleDescriptorAction = configure;
			return Self;
		}

		public DataframeEvaluationRegressionMetricsDescriptor RSquared(Func<FluentDictionary<string, object>, FluentDictionary<string, object>> selector)
		{
			RSquaredValue = selector?.Invoke(new FluentDictionary<string, object>());
			return Self;
		}

		protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
		{
			writer.WriteStartObject();
			if (HuberDescriptor is not null)
			{
				writer.WritePropertyName("huber");
				JsonSerializer.Serialize(writer, HuberDescriptor, options);
			}
			else if (HuberDescriptorAction is not null)
			{
				writer.WritePropertyName("huber");
				JsonSerializer.Serialize(writer, new DataframeEvaluationRegressionMetricsHuberDescriptor(HuberDescriptorAction), options);
			}
			else if (HuberValue is not null)
			{
				writer.WritePropertyName("huber");
				JsonSerializer.Serialize(writer, HuberValue, options);
			}

			if (MseValue is not null)
			{
				writer.WritePropertyName("mse");
				JsonSerializer.Serialize(writer, MseValue, options);
			}

			if (MsleDescriptor is not null)
			{
				writer.WritePropertyName("msle");
				JsonSerializer.Serialize(writer, MsleDescriptor, options);
			}
			else if (MsleDescriptorAction is not null)
			{
				writer.WritePropertyName("msle");
				JsonSerializer.Serialize(writer, new DataframeEvaluationRegressionMetricsMsleDescriptor(MsleDescriptorAction), options);
			}
			else if (MsleValue is not null)
			{
				writer.WritePropertyName("msle");
				JsonSerializer.Serialize(writer, MsleValue, options);
			}

			if (RSquaredValue is not null)
			{
				writer.WritePropertyName("r_squared");
				JsonSerializer.Serialize(writer, RSquaredValue, options);
			}

			writer.WriteEndObject();
		}
	}
}